#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7, P = 1e9 + 7;

// 并查集
// avr:O(m) worse:(m logn) 
// n个数，m次询问/合并操作
int n, m, fa[N];
string str;

int findset(int x) {
	if(x == fa[x])
		return x;
		
	return fa[x] = findset(fa[x]); 
}
int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++)	
		fa[i] = i;
	for(int i = 1; i <= m; i++) {
		int x, y;
		cin >> str >> x >> y;
		if(str[0] == 'M') { // 合并集合 
			int fx = findset(x);
			int fy = findset(y);
			if(fx == fy)
				continue;
			fa[fx] = fy; 
		} else { // 查询 
			int fx = findset(x);
			int fy = findset(y);
			if(fx == fy)
				cout << "同一集合\n";
			else
				cout << "不同集合\n"; 
		}
	}
	
	return 0;
} 
